#include <allegro.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


#include "lib/keyboard.h"
#include "lib/game.h"
#include "lib/map.h"
#include "lib/tile.h"
#include "lib/sprite.h"




int mW_SCREEN_WIDTH  = 800;
int mW_SCREEN_HEIGHT = 600;

int main(int argc, char * argv[])
{

	if (allegro_init() != 0)
	{
		printf("Allegro failed to init.\n");
		return 0;
	}
	
	set_color_depth(24);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, mW_SCREEN_WIDTH, mW_SCREEN_HEIGHT, 0, 0) != 0)
	{
		printf("Error setting graphics mode\n");
		return 0;
	}
	
	if (install_timer() != 0)
	{
		printf("Error installing timer\n");
		return 0;
	}
	
	if (mW_keyboard_init() == 0)
	{
		printf("Error initializing keyboard\n");
		return 0;
	}
	
	if (mW_tiles_init() == 0)
	{
		printf("Error initializing tiles\n");
		return 0;
	}
	
	if (mW_tiles_load("data/tiles/") == 0)
	{
		printf("Error loading tiles\n");
		return 0;
	}
	
	if (mW_mouse_init() == 0)
	{
		printf("Error initializing mouse\n");
		return 0;
	}
	
	if (mW_interface_init() == 0)
	{
		printf("Error initializing interface\n");
		return 0;
	}
	
	if (mW_sprite_init() == 0)
	{
		printf("Error initializing sprites\n");
		return 0;
	}
	
	set_palette(desktop_palette);
	
	acquire_screen();
	clear_to_color(screen, makecol(0x0, 0x0, 0x0));
	release_screen();
	
	mW_game();
	
	return 1;
	
}
END_OF_MAIN()
